using System;
using System.Collections;
using System.Collections.Generic;
using Newtonsoft.Json.Linq;
using UnityEngine;
using UnityEngine.UI;

public class OrderNotificationPanel : BasePanel, IInitializable
{
    public Image orderImage;
    public Text orderText;
    public Text starText;
    private int type;

    public void Initialize(object data)
    {
        Debug.Log("OrderNotificationPanel initialized" + data);
    }
    public override void OnClose()
    {
        base.OnClose(); // 调用基类的 OnClose 方法
        // 在面板关闭时执行的逻辑
        Debug.Log("OrderNotificationPanel closed");
    }

    public override void OnOpen()
    {
        base.OnOpen();
        // 在面板打开时执行的逻辑
        Debug.Log("OrderNotificationPanel opened");
        RandomInfo();
    }

    public void OnCloseClick()
    {
        // 关闭面板
        PanelManager.Instance.ClosePanel<OrderNotificationPanel>();
    }

    public void OnPrepareFoodClick()
    {
        JObject data = new JObject
        {
            ["Type"] = type,
            ["Order"] = 3,
            ["Star"] = 9
        };
        GlobalEventManager.EmitEvent<JObject>("OrderNotification", data);
        OnCloseClick();
    }

    public void RandomInfo()
    {
        type = UnityEngine.Random.Range(0, Constants.GOODS_COUNT);
        Sprite[] sprites = ResManager.Instance.GetGoodsIcons();
        orderImage.sprite = sprites[type];

        orderText.text = "x" + 3;
        starText.text = "x" + 9;
    }
}